/**
 * Created by Administrator on 2017/6/9.
 */
import React from 'react';
import
{
    View,
    Text,
    TouchableHighlight,
    Image,
    WebView,
}
    from 'react-native';

import  BaseComponent, {base} from '../../base/Base' ;

let {USER_INFO}=base.fields;
export default class ButlerFoundHouse extends BaseComponent {
    constructor(props) {
        super(props);
        this.state = {
            butlerId: this.props.navigation.state.params.butlerId,
            tagInfo:this.props.navigation.state.params.tagInfo,
            isParamsOk:false,
        };

    }
    componentDidMount() {
        base.Store.get(USER_INFO)
            .then(userInfo=>{

                // alert(JSON.stringify(userInfo))
                /*通过自定义不同的标签配置不同的参数*/
                var checkedCase=this.state.tagInfo;
                if(checkedCase==="管家配房"){
                    let url=this.state.butlerId+'?userId='+userInfo.userId+'&userName='+userInfo.nickName+'&cellPhone='+userInfo.cellPhone;
                    this.setState({
                        butlerId:url,
                        isParamsOk:true,
                    })
                }else if(checkedCase==="房租月付"){
                    let url=this.state.butlerId+'?mobile=15737976922&loginStatus='+userInfo.commonPlatfromToke+'&userId='+userInfo.userId+'&openId='+userInfo.openId;
                    this.setState({
                        butlerId:url,
                        isParamsOk:true,
                    })
                }else if(checkedCase==="公寓好房"){
                   //已经拼凑好链接了
                    this.setState({
                        isParamsOk:true,
                    })
                }

            })
            .catch(error=>{

            });
    }
    static navigationOptions = ({navigation}) => ({
        // title: navigation.state.params.goodId,
        title:navigation.state.params.title,
    });

    _onShouldStartLoadWithRequest = (event) => {
        alert(JSON.stringify(event))
        return true;
    };
    render() {
       let url= this.state.butlerId;
       let responseOk= this.state.isParamsOk;
       if(responseOk){
           return (
               <WebView
                   onShouldStartLoadWithRequest={this._onShouldStartLoadWithRequest}
                   domStorageEnabled={true}
                   decelerationRate="normal"
                   startInLoadingState={true}
                   source={{uri: url}}
                   style={{width:'100%',height:'100%'}}
                   scrollEnabled={false}
                   bounces={false}
                   contentInset={{top: 0, left: 0}}
                   automaticallyAdjustContentInsets={true}
                   javaScriptEnabled={true}
                   onNavigationStateChange={(navState) => {
                   }}
               />
           )
       }else {
           return (<View/>)
       }
    }


}

